<template>
    <div>
        <el-container>
            <el-header style="padding:0;">
                <div class="head">
                    <div>
                        <img src="../../../public/20230318112820.png" style="width: 50px;margin-left: 0px;" alt="">
                    </div>
                    <el-menu :default-active="$route.path" class="nav" mode="horizontal" background-color="#785545"
                        text-color="#fff" active-text-color="#fcba47" router>
                        <el-menu-item index="/home/index" style="height: 60px;">首页</el-menu-item>
                        <el-menu-item index="/home/activity">活动</el-menu-item>
                        <el-menu-item index="/home/community">社区</el-menu-item>
                        <el-menu-item index="5">话题</el-menu-item>
                        <el-input placeholder="请输入内容" style="width: 250px;" class="input" suffix-icon="el-icon-search"
                            size="small">
                        </el-input>
                        <el-menu-item index="/home/usercenter">用户中心</el-menu-item>
                        <el-menu-item index="/home/login">登录</el-menu-item>
                        <el-menu-item index="/home/register">注册</el-menu-item>
                    </el-menu>

                </div>
            </el-header>
            <el-main style="padding:15px 0">
                <div class="push">
                    <div class="bcimg">
                        <img src="../../../public/pushmt.png" alt="">
                    </div>
                    <div class="card-main">
                        <el-form ref="form" :model="form" style="box-sizing: border-box;padding-left:150px;background-color: #fff;" >
                            <el-form-item label="活动标题" class="form-item">
                                <el-input v-model="form.title" style="width:70%;" placeholder="标题"></el-input>
                            </el-form-item>
                            <el-form-item label="你的想法" class="form-item">
                                <textarea v-model="form.detail"  cols="102" rows="15" style="resize: none;border: 1px solid #dcdfe6; border-radius: 6px; outline: none;font-size: 14px; color: #606266;padding: 10px;" placeholder="帖子内容"></textarea>
                            </el-form-item>
                            <p style="color: #ff76be;margin: 10px 0;">上传封面图片</p>
                            <el-upload class="avatar-uploader" action="https://jsonplaceholder.typicode.com/posts/"
                                :show-file-list="false" :on-success="handleAvatarSuccess"
                                :before-upload="beforeAvatarUpload">
                                <div class="el-upload">
                                    <img v-if="form.pic" :src="form.pic" class="avatar">
                                    <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                                </div>
                            </el-upload>
                            <p style="color: #ff76be;">封面设置建议尺寸为2:1</p>
                            <el-form-item style="margin-top: 20px;">
                                <el-radio-group v-model="form.is_original">
                                    <el-radio label="原创"></el-radio>
                                    <el-radio label="非原创"></el-radio>
                                </el-radio-group>
                                <el-radio-group style="margin-left: 50px;" v-model="form.is_transport">
                                    <el-radio label="允许转载"></el-radio>
                                    <el-radio label="不允许转载"></el-radio>
                                </el-radio-group>
                            </el-form-item>
                            <el-form-item label="关联设置">
                                <el-switch v-model="form.is_relate"></el-switch>
                            </el-form-item>
                            <el-form-item v-show="form.is_relate" style="border: 1px solid #dcdfe6;width: 90%;border-radius: 5px;">
                                <div class="relate-box">
                                    <p>推荐标签</p>
                                    <div class="relate-tags">
                                        <div class="tags-box" v-for="t in tags" :key="t.id">
                                            <span :class="t.isActive? 'tags-btn active':'tags-btn'" @click="t.isActive=!t.isActive">{{t.name}}</span>
                                        </div>
                                    </div>
                                    <hr>
                                    <p>关联版块</p>
                                    <div class="relate-modules">
                                        <div class="tags-box" v-for="m in modules" :key="m.mid">
                                            <span :class="m.isActive? 'tags-btn active':'tags-btn'" @click="moduleActive(m.mid)">{{m.name}}</span>
                                        </div>
                                    </div>
                                </div>
                            </el-form-item>
                            <el-form-item style="margin-bottom:15px">
                                <el-button type="warning" style="background-color: #f8b107;">发布帖子</el-button>
                            </el-form-item>
                        </el-form>
                    </div>
                    
                </div>
            </el-main>
        </el-container>
    </div>
</template>
   
<script>
export default {
    data() {
        return {
            form: {
                title: '',//#帖子标题
                dates: 1680183891066,//#发表时间
                detail: '',//#帖子内容
                userid: -1,//#关联用户的ID
                pic: '',//封面图片(内容图片)
                is_original: false,//是否原创
                is_transport: false,//是否允许转载
                is_relate: false,//是否关联标签/板块
                tags: '',//标签
                module: '三次元',//板块模块
                play_id: -1,//关联帖子的ID(活动帖子使用)
            },
            tags: [
                {
                    tid: 0,
                    name: '扩列',
                    value: '#扩列',
                    isActive: false,
                },
                {
                    tid: 1,
                    name: '同人CP绘画',
                    value: '#同人CP绘画',
                    isActive: false,
                },
                {
                    tid: 2,
                    name: '动漫',
                    value: '#动漫',
                    isActive: false,
                },
                {
                    tid: 3,
                    name: '女装',
                    value: '#女装',
                    isActive: false,
                },
                {
                    tid: 4,
                    name: '手办',
                    value: '#手办',
                    isActive: false,
                },
            ],
            modules: [
                {
                    mid: 0,
                    name: '不关联',
                    isActive: false,
                }, {
                    mid: 1,
                    name: '三次元',
                    isActive: false,
                }, {
                    mid: 2,
                    name: '扩列',
                    isActive: false,
                }, {
                    mid: 3,
                    name: '求助',
                    isActive: false,
                }, {
                    mid: 4,
                    name: 'Cosplay',
                    isActive: false,
                }, {
                    mid: 5,
                    name: '壁纸',
                    isActive: false,
                },
            ]
        }
    },
    methods: {
        handleAvatarSuccess(res, file) {
            this.form.pic = URL.createObjectURL(file.raw);
        },
        beforeAvatarUpload(file) {
            const isJPG = file.type === 'image/jpeg';
            const isLt2M = file.size / 1024 / 1024 < 2;

            if (!isJPG) {
                this.$message.error('上传头像图片只能是 JPG 格式!');
            }
            if (!isLt2M) {
                this.$message.error('上传头像图片大小不能超过 2MB!');
            }
            return isJPG && isLt2M;
        },
        moduleActive(id){
            for(let i=0;i<this.modules.length;i++){
                if(this.modules[i].isActive){
                    this.modules[i].isActive=false
                }
            }
            console.log(id);
            this.modules[id].isActive=!this.modules[id].isActive
        }
    },
}
</script>
  
<style lang="scss" scoped>
.head {
    background-color: #785545;
    display: flex;
    height: 60px;
    justify-content: center;

    .nav {
        width: 1000px;
        height: 61px;
        display: flex;
        align-items: center;
        justify-content: space-evenly;

        .input {
            &.foucs {
                border-color: #785545;
            }
        }
    }
}
.form-item{
    padding: 15px 0;
}
// 关联内容css样式
.relate-box{
    width: 70%;
    height: 400px;
    padding: 15px;
    .tags-box{
        display: inline-block;
        margin: 5px 15px;
        height: 150px;
        .tags-btn{
            height: 30px;
            padding: 5px 10px;
            text-align: center;
            line-height: 30px;
            font-size: 14px;
            color: #666;
            background-color: #f4f5f7;
            border: 1px solid #f4f5f7;
            border-radius:30px;
            display: inline-block;
            &:hover{
                background-color: #fff;
                border: 1px solid #f8b107;
                color: #f8b107;
            }
            &.active{
                background-color: #fff;
                border: 1px solid #f8b107;
                color: #f8b107;
            }
        }
    }
}

.push {
    display: flex;
    margin: 30px auto;
    padding-left: 200px;

    .bcimg {
        width: 200px;
        height: 500px;

        img {
            margin-top: 100px;
            width: 200px;
        }
    }

    .card-main {
        width: 1200px;
        padding: 30px 0;
        background-color: #fff;
        border-radius: 5px;
    }
}

/*****上传图片css样式*****/
.avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    >img{
        width: 100%;
    }
}

.avatar-uploader .el-upload:hover {
    border-color: #409EFF;
}

.avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
}

.avatar {
    width: 178px;
    height: 178px;
    display: block;
}
</style>
  